/*
 * PantallaJugador.java
 *
 * Created on 31 de agosto de 2008, 03:29 PM
 */
package GUI;

import java.awt.event.WindowEvent;
import java.util.ArrayList;
import java.util.List;
import javax.swing.ImageIcon;
import Juego.*;

/**
 *
 * @author  Propietario
 */
public class PantallaVScpu extends javax.swing.JFrame {

    Byte Pl;
    Byte Cl;
    Jugador JP;
    Jugador JC;
    List imagenes;
    int cartaReves;

    public PantallaVScpu(List imagen) {
        imagenes = new ArrayList(imagen);
        Pl = 3;
        Cl = 3;
        initComponents();
        JP = new Jugador(true);
        JC = new Jugador(false);
        jLCarta1.setIcon((ImageIcon) imagenes.get(JP.pedirCarta()));
        jLCarta2.setIcon((ImageIcon) imagenes.get(JP.pedirCarta()));
        jLPeque1.setIcon((ImageIcon) imagenes.get(JC.pedirCarta()));
        //jLPeque2.setIcon((ImageIcon) imagenes.get(JC.pedirCarta()));
        cartaReves = JC.pedirCarta();
        jLReves.setIcon((ImageIcon) imagenes.get(53));
        this.setTitle("Juego");
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jBCarta = new javax.swing.JButton();
        jSeparator1 = new javax.swing.JSeparator();
        jBParar = new javax.swing.JButton();
        jLCarta1 = new javax.swing.JLabel();
        jLCarta2 = new javax.swing.JLabel();
        jLUsuario = new javax.swing.JLabel();
        jLContrincante = new javax.swing.JLabel();
        jLPeque1 = new javax.swing.JLabel();
        jLReves = new javax.swing.JLabel();
        jLCarta3 = new javax.swing.JLabel();
        jLCarta4 = new javax.swing.JLabel();
        jLCarta5 = new javax.swing.JLabel();
        jLCarta6 = new javax.swing.JLabel();
        jLPeque2 = new javax.swing.JLabel();
        jLPeque3 = new javax.swing.JLabel();
        jLPeque4 = new javax.swing.JLabel();
        jLPeque5 = new javax.swing.JLabel();
        jMenuBar1 = new javax.swing.JMenuBar();
        jMenu1 = new javax.swing.JMenu();
        jMenu2 = new javax.swing.JMenu();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jPanel1.setBackground(new java.awt.Color(0, 0, 0));

        jBCarta.setBackground(new java.awt.Color(0, 0, 0));
        jBCarta.setFont(new java.awt.Font("Arial", 1, 11));
        jBCarta.setForeground(new java.awt.Color(204, 102, 0));
        jBCarta.setText("Carta");
        jBCarta.setFocusable(false);
        jBCarta.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBCartaActionPerformed(evt);
            }
        });

        jSeparator1.setBackground(new java.awt.Color(204, 102, 0));
        jSeparator1.setForeground(new java.awt.Color(204, 102, 0));

        jBParar.setBackground(new java.awt.Color(0, 0, 0));
        jBParar.setFont(new java.awt.Font("Arial", 1, 11));
        jBParar.setForeground(new java.awt.Color(204, 102, 0));
        jBParar.setText("Plantar");
        jBParar.setFocusable(false);
        jBParar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBPararActionPerformed(evt);
            }
        });

        jLUsuario.setFont(new java.awt.Font("Arial", 1, 14));
        jLUsuario.setForeground(new java.awt.Color(204, 102, 0));
        jLUsuario.setText("Usuario");

        jLContrincante.setFont(new java.awt.Font("Arial", 1, 14));
        jLContrincante.setForeground(new java.awt.Color(204, 102, 0));
        jLContrincante.setText("CPU");

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, 763, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLUsuario, javax.swing.GroupLayout.PREFERRED_SIZE, 268, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLContrincante, javax.swing.GroupLayout.PREFERRED_SIZE, 220, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(70, 70, 70)
                        .addComponent(jLPeque1, javax.swing.GroupLayout.PREFERRED_SIZE, 106, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLReves, javax.swing.GroupLayout.PREFERRED_SIZE, 106, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(jLPeque2, javax.swing.GroupLayout.PREFERRED_SIZE, 106, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLPeque3, javax.swing.GroupLayout.PREFERRED_SIZE, 106, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLPeque4, javax.swing.GroupLayout.PREFERRED_SIZE, 106, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLPeque5, javax.swing.GroupLayout.PREFERRED_SIZE, 106, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(47, 47, 47)
                        .addComponent(jLCarta1, javax.swing.GroupLayout.PREFERRED_SIZE, 108, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLCarta2, javax.swing.GroupLayout.PREFERRED_SIZE, 112, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLCarta3, javax.swing.GroupLayout.PREFERRED_SIZE, 108, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLCarta4, javax.swing.GroupLayout.DEFAULT_SIZE, 144, Short.MAX_VALUE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLCarta5, javax.swing.GroupLayout.PREFERRED_SIZE, 111, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jLCarta6, javax.swing.GroupLayout.PREFERRED_SIZE, 109, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(268, 268, 268)
                        .addComponent(jBCarta, javax.swing.GroupLayout.PREFERRED_SIZE, 77, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jBParar, javax.swing.GroupLayout.PREFERRED_SIZE, 84, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(17, 17, 17)
                .addComponent(jLUsuario)
                .addGap(18, 18, 18)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLCarta6, javax.swing.GroupLayout.DEFAULT_SIZE, 164, Short.MAX_VALUE)
                    .addComponent(jLCarta5, javax.swing.GroupLayout.DEFAULT_SIZE, 164, Short.MAX_VALUE)
                    .addComponent(jLCarta4, javax.swing.GroupLayout.DEFAULT_SIZE, 164, Short.MAX_VALUE)
                    .addComponent(jLCarta3, javax.swing.GroupLayout.DEFAULT_SIZE, 164, Short.MAX_VALUE)
                    .addComponent(jLCarta1, javax.swing.GroupLayout.DEFAULT_SIZE, 164, Short.MAX_VALUE)
                    .addComponent(jLCarta2, javax.swing.GroupLayout.DEFAULT_SIZE, 164, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jBCarta)
                    .addComponent(jBParar))
                .addGap(32, 32, 32)
                .addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLContrincante)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
                    .addComponent(jLPeque4, javax.swing.GroupLayout.DEFAULT_SIZE, 159, Short.MAX_VALUE)
                    .addComponent(jLPeque3, javax.swing.GroupLayout.DEFAULT_SIZE, 159, Short.MAX_VALUE)
                    .addComponent(jLPeque5, javax.swing.GroupLayout.DEFAULT_SIZE, 159, Short.MAX_VALUE)
                    .addComponent(jLPeque1, javax.swing.GroupLayout.PREFERRED_SIZE, 159, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLPeque2, javax.swing.GroupLayout.DEFAULT_SIZE, 159, Short.MAX_VALUE)
                    .addComponent(jLReves, javax.swing.GroupLayout.PREFERRED_SIZE, 159, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(83, 83, 83))
        );

        jMenu1.setText("Archivo");
        jMenuBar1.add(jMenu1);

        jMenu2.setText("Acerca de...");
        jMenuBar1.add(jMenu2);

        setJMenuBar(jMenuBar1);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jBCartaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBCartaActionPerformed
        // TODO add your handling code here:
        Byte b = JP.pedirCarta();
        switch (Pl) {
            case 3:
                jLCarta3.setIcon((ImageIcon) imagenes.get(b));
                break;
            case 4:
                jLCarta4.setIcon((ImageIcon) imagenes.get(b));
                break;
            case 5:
                jLCarta5.setIcon((ImageIcon) imagenes.get(b));
                break;
            case 6:
                jLCarta6.setIcon((ImageIcon) imagenes.get(b));
                break;
        }
        if (JP.sePaso()) {
            jBCarta.setEnabled(false);
        }
        Pl++;
        System.out.println("pidiendo carta");
    }//GEN-LAST:event_jBCartaActionPerformed

    private void jBPararActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBPararActionPerformed
        // TODO add your handling code here:
        JP.planto();
        jBParar.setEnabled(false);
        jBCarta.setEnabled(false);
        while (JC.sum() < 17 && !JC.sePaso()) {
            System.out.println("VA EL PC");
            Byte b = JC.pedirCarta();
            switch (Cl) {
                case 3:
                    jLPeque2.setIcon((ImageIcon) imagenes.get(b));
                    break;
                case 4:
                    jLPeque3.setIcon((ImageIcon) imagenes.get(b));
                    break;
                case 5:
                    jLPeque4.setIcon((ImageIcon) imagenes.get(b));
                    break;
                case 6:
                    jLPeque5.setIcon((ImageIcon) imagenes.get(b));
                    break;
            }
            
            
            jLReves.setIcon((ImageIcon) imagenes.get(cartaReves));            
            Cl++;
        } 
        if(JC.sum()>17 || !JC.sePaso())
        {
            JC.planto();
        }
        if (JC.sePaso()){
            System.err.println("SE PASO EL PC");
        }
    //jBRepartir.enable(true);

    }//GEN-LAST:event_jBPararActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jBCarta;
    private javax.swing.JButton jBParar;
    private javax.swing.JLabel jLCarta1;
    private javax.swing.JLabel jLCarta2;
    private javax.swing.JLabel jLCarta3;
    private javax.swing.JLabel jLCarta4;
    private javax.swing.JLabel jLCarta5;
    private javax.swing.JLabel jLCarta6;
    private javax.swing.JLabel jLContrincante;
    private javax.swing.JLabel jLPeque1;
    private javax.swing.JLabel jLPeque2;
    private javax.swing.JLabel jLPeque3;
    private javax.swing.JLabel jLPeque4;
    private javax.swing.JLabel jLPeque5;
    private javax.swing.JLabel jLReves;
    private javax.swing.JLabel jLUsuario;
    private javax.swing.JMenu jMenu1;
    private javax.swing.JMenu jMenu2;
    private javax.swing.JMenuBar jMenuBar1;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JSeparator jSeparator1;
    // End of variables declaration//GEN-END:variables
    // cerrar ventana

    @Override
    protected void processWindowEvent(WindowEvent e) {
        super.processWindowEvent(e);
        if (e.getID() == WindowEvent.WINDOW_CLOSING) {
            System.exit(0);
        }
    }
}
